package com.hzdl.hotel.service.impl;

import com.hzdl.hotel.bean.User;
import com.hzdl.hotel.mapper.UserMapper;
import com.hzdl.hotel.service.UserService;
import com.hzdl.hotel.vo.UserVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class UserServiceImpl implements UserService {

    @Autowired
    private UserMapper userMapper;


    @Override
    public User findByNameAndId(User user) {
        return userMapper.findByNameAndId(user);
    }

    @Override
    public int registerUser(User user) {
        return userMapper.registerUser(user);
    }

    @Override
    public int changePwd(UserVo userVo) {
        return userMapper.changePwd(userVo);
    }

    @Override
    public User findByLoginId(UserVo userVo) {
        return userMapper.findByLoginId(userVo);
    }

    @Override
    public List<Map<String, Object>> allUser() {
        List<Map<String,Object>> userList = new ArrayList<>();
        Map<String,Object> map = new HashMap<>();
        List<User> allUser = userMapper.allUser();
        allUser.stream().forEach(user ->{
            map.put("编号",user.getUserId());
            map.put("名字",user.getLoginName());
            map.put("性别",user.getSex());
            map.put("住址",user.getAddress());
            userList.add(map);
        });

        return userList;
    }


}
